Remove["Global`*"]
f[x_]=Sin[x];
(* f(x) =sin(x). Estimate f'(pi/2) med back, forward och center för h=10^-k, k=1,2,3.. tills datorn dör. Jämför f'[pi/2]=cos(pi/2)=0*)
forward[x_,h_]:=((f[x+h]-f[x])/h);
backward[x_,h_]:=((f[x]-f[x-h])/h);
center[x_,h_]:=((f[x+h]-f[x-h])/(2h));
k=1;
Print["------------"]
While[forward[Pi/2,N[10^-k]]≠0,Print["Forward[Pi/2, h=",N[10^-k],"]=",forward[Pi/2,N[10^-k]]];k++];

Print["Forward[Pi/2, h=",N[10^-k],"]=",forward[Pi/2,N[10^-k]]]
Print["Med k=",k," får vi 0"]
Print["------------"]
k=1;
While[backward[Pi/2,N[10^-k]]≠0,Print["Backward[Pi/2, h=",N[10^-k],"]=",backward[Pi/2,N[10^-k]]];k++];
Print["Backward[Pi/2, h=",N[10^-k],"]=",backward[Pi/2,N[10^-k]]]
Print["Med k=",k," får vi 0"]
Print["------------"]
k=1;
While[center[Pi/2,N[10^-k]]≠0;k++];Print["Center[Pi/2, h=",N[10^-k],"]=",center[Pi/2,N[10^-k]]]
Print["Med k=",k," får vi 0"]